<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "{{%role}}".
 *
 * @property int $id
 * @property string $name 职位名称
 * @property int $sort
 * @property mixed branch
 * @property mixed user
 */
class Source extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['type_id','branch_id','content','meeting_date','name'], 'required'],
            [['type_id','branch_id','meeting_date'], 'integer'],
            [['name','content'], 'string'],
        ];
    }

    public function extraFields()
    {
        $fields['branch_name'] = function (){
            return $this->branch->name;
        };
        $fields['user_name'] = function (){
            return $this->user->username;
        };
        return $fields;
    }

    public function getBranch(){
        return $this->hasOne(Branch::class,['id'=>'branch_id']);
    }

    public function getUser() {
        return $this->hasOne(User::class,['id'=>'user_id']);
    }

}
